<!DOCTYPE html>
<html>
<head>
<title>Electric Charges on an Axis</title>
<style>
  body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    background-color: #f0f0f0;
  }
  canvas {
    border: 1px solid #ccc;
    background-color: #fff;
  }
</style>
</head>
<body>
<canvas id="physicsCanvas" width="800" height="300"></canvas>
<script>
  const canvas = document.getElementById('physicsCanvas');
  const ctx = canvas.getContext('2d');

  // --- Constants and Coordinates ---
  const yAxis = canvas.height / 2;
  const chargePos1 = 250;
  const chargePos2 = 550;
  const axisStart = 50;
  const axisEnd = 750;
  const chargeRadius = 7;
  const chargeLabelY = yAxis + 50;
  const regionLabelY = yAxis - 70;
  const dashLineTop = yAxis - 110;
  const dashLineBottom = yAxis + 110;

  ctx.strokeStyle = 'black';
  ctx.fillStyle = 'black';
  ctx.lineWidth = 2;

  // --- Draw X-axis with arrowheads ---
  ctx.beginPath();
  ctx.moveTo(axisStart, yAxis);
  ctx.lineTo(axisEnd, yAxis);
  ctx.stroke();

  // Right arrowhead
  ctx.beginPath();
  ctx.moveTo(axisEnd, yAxis);
  ctx.lineTo(axisEnd - 12, yAxis - 6);
  ctx.stroke();
  ctx.beginPath();
  ctx.moveTo(axisEnd, yAxis);
  ctx.lineTo(axisEnd - 12, yAxis + 6);
  ctx.stroke();

  // Left arrowhead
  ctx.beginPath();
  ctx.moveTo(axisStart, yAxis);
  ctx.lineTo(axisStart + 12, yAxis - 6);
  ctx.stroke();
  ctx.beginPath();
  ctx.moveTo(axisStart, yAxis);
  ctx.lineTo(axisStart + 12, yAxis + 6);
  ctx.stroke();

  // --- Draw Dashed Lines ---
  ctx.beginPath();
  ctx.setLineDash([5, 5]);
  ctx.lineWidth = 1.5;
  // Line at +3Q
  ctx.moveTo(chargePos1, dashLineTop);
  ctx.lineTo(chargePos1, dashLineBottom);
  // Line at -Q
  ctx.moveTo(chargePos2, dashLineTop);
  ctx.lineTo(chargePos2, dashLineBottom);
  ctx.stroke();
  
  // Reset line style
  ctx.setLineDash([]);
  ctx.lineWidth = 2;

  // --- Draw Charges (solid circles) ---
  // +3Q charge
  ctx.beginPath();
  ctx.arc(chargePos1, yAxis, chargeRadius, 0, 2 * Math.PI);
  ctx.fill();

  // -Q charge
  ctx.beginPath();
  ctx.arc(chargePos2, yAxis, chargeRadius, 0, 2 * Math.PI);
  ctx.fill();


  // --- Draw Labels ---
  ctx.font = 'bold 28px "Times New Roman"';
  ctx.textAlign = 'center';
  ctx.textBaseline = 'middle';

  // Region labels
  ctx.fillText('Region I', (axisStart + chargePos1) / 2 + 20, regionLabelY);
  ctx.fillText('Region II', (chargePos1 + chargePos2) / 2, regionLabelY);
  ctx.fillText('Region III', (chargePos2 + axisEnd) / 2, regionLabelY);
  
  // Charge labels
  ctx.font = 'bold 26px "Times New Roman"';
  ctx.fillText('+3Q', chargePos1, chargeLabelY);
  ctx.fillText('-Q', chargePos2, chargeLabelY);
  
  // Axis label
  ctx.font = 'bold 28px "Times New Roman"';
  ctx.textAlign = 'left';
  ctx.fillText('+x', axisEnd + 15, yAxis);

</script>
</body>
</html>